import com.atguigu.Pojo.Employee;
import com.atguigu.mapper.Employeemapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package PACKAGE_NAME
 * @date 2024/4/25 下午8:55
 */
public class testmybatis {
    private SqlSession session;
    // junit会在每一个@Test方法前执行@BeforeEach方法

    @BeforeEach
    public void init() throws IOException {
        session = new SqlSessionFactoryBuilder()
                .build(
                        Resources.getResourceAsStream("mybatis-config.xml"))
                .openSession();
    }

    @Test
    public void test() {
        Employeemapper mapper = session.getMapper(Employeemapper.class);
        List<Employee> query = mapper.query((String) null, 101.0);
        for (Employee employee : query) {
            System.out.println("employee = " + employee);
        }

    }

    @AfterEach
    public void clear() {
session.commit();
        session.close();
    }
}
